package dao

import (
	"log"

	"gitee.com/Yu-eng/Myproject/my-go-blog/models"
)

func GetAllCategory() []models.Category {
	rows, err := DB.Query("select * from blog_category")
	if err != nil {
		log.Println("GetAllCategory 查询出错:", err)
	}
	//拿到数据 序列化为数据结构
	var categorys []models.Category
	for row.Next() {
		var category models.Category
		//这里将查询的行 的值赋给category
		err = rows.Scan(&category.Cid, &category.Name, &category.CreateAt, &category.UpdateAt)
		if err != nil {
			log.Println("GetAllCategory rows.scan 出错：", err)
			return nil, err
		}
		categorys = append(categorys, category)
	}
}
